//
//  RwdCommonController.swift
//  Weibo_rwd
//
//  Created by 任文迪 on 16/7/9.
//  Copyright © 2016年 spaceX. All rights reserved.
//

import UIKit

class RwdCommonController: UITableViewController {
    
    var  isLogin: Bool = RwduserAccountViewModel.shareUserAccount.isLogin
    
    //添加访客视图
    var visitorView: RwdVisitorView?
    
    override func loadView() {
        
        //通过登录状态选择控制器的view
        if isLogin {
            super.loadView()
        }else {
            
            visitorView = RwdVisitorView()
            
            self.view = visitorView
            
//            visitorView?.backgroundColor = UIColor.whiteColor()
            
            setUpNavUI()
            //传递visitorview的按钮点击事件的闭包
            visitorView?.loginClosure = { [weak self] in
                self?.loginToOAuth()
            }
            
        
        }
        
        
        
    }
    

    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    func setUpNavUI() {
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "loginAction")
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "registerAction")
        
    }
    
    
    func loginAction() {
        
        print("点击了登录按钮")
        //设置跳转
        loginToOAuth()
        
    }
    
    func registerAction() {
        
        print("点击了注册按钮")
        //设置跳转
        loginToOAuth()
        
    }
    
    //设置跳转OAuthController的方法
    func loginToOAuth() {
        //创建一个实例化的控制器
        let OAVc = RwdOAuthController()
        //创建一个顶部的导航控制器
        let nav = UINavigationController(rootViewController: OAVc)
        //设置跳转
        presentViewController(nav, animated: true, completion: nil)
        
    }
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

 }
